package com.zhu.service.smtp.controller;

import com.zhu.commons.utils.MailUtils;
import com.zhu.commons.utils.R;
import com.zhu.service.smtp.service.mail.CodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.apache.bcel.classfile.Code;
import org.checkerframework.dataflow.qual.TerminatesExecution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("api/mail")
@RestController
@Api(tags = "发送邮件")
public class MailSendController {
    @Autowired
    private CodeService codeService;

    @ApiOperation(value = "验证码")
    @PostMapping("code/{email}")
    public R getCode(@PathVariable String email){
        /**
         * 校验验证码
         */
        if(!MailUtils.isEmail(email)|| StringUtils.isEmpty(email)){
            return R.error().message("请输入合法的邮箱！");
        }
        String code=codeService.getCode(email);
        return R.ok().data("code",code);
    }


}
